<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Gitlab webhook 配置企业微信机器人 | Jeffery Blog</title><meta name="keywords" content="hexo,性能优化"><meta name="author" content="志非"><meta name="copyright" content="志非"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="hxo 性能优化">
<meta property="og:type" content="article">
<meta property="og:title" content="Gitlab webhook 配置企业微信机器人">
<meta property="og:url" content="https://fif.gitee.io/blog/2021/04/24/tools/gitlab/index/index.html">
<meta property="og:site_name" content="Jeffery Blog">
<meta property="og:description" content="hxo 性能优化">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/FIF/pic-beg/raw/master/images/vue/Hexo-logo.png">
<meta property="article:published_time" content="2021-04-23T16:00:00.000Z">
<meta property="article:modified_time" content="2021-06-20T16:13:05.936Z">
<meta property="article:author" content="志非">
<meta property="article:tag" content="hexo">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/FIF/pic-beg/raw/master/images/vue/Hexo-logo.png"><link rel="shortcut icon" href="/blog/img/home/avatar.jpeg"><link rel="canonical" href="https://fif.gitee.io/blog/2021/04/24/tools/gitlab/index/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.js" defer></script><script async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><script>(adsbygoogle = window.adsbygoogle || []).push({
  google_ad_client: '',
  enable_page_level_ads: 'true'
});</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: {"appId":"QYKLQ4BSGP","apiKey":"d45fc66694b4260b20711a30fdb5c4e1","indexName":"jeffery-blog","hits":{"per_page":6},"languages":{"input_placeholder":"搜索文章","hits_empty":"找不到您查询的内容：${query}","hits_stats":"找到 ${hits} 条结果，用时 ${time} 毫秒"}},
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: {"limitDay":200,"position":"top","messagePrev":"本文修改于","messageNext":"天前，如果本文有一定的时效性，那么本文可能已经失效~"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2021-06-21 00:13:05'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/blog/atom.xml" title="Jeffery Blog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><img class="load-image" src= "" data-lazy-src="/blog/img/loading.gif" alt=""/></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src= "" data-lazy-src="/blog/img/home/avatar.jpeg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">12</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">6</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 媒体</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/books/"><i class="fa-fw fas fa-book"></i><span> 阅读</span></a></li><li><a class="site-page child" href="/blog/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/blog/movies/"><i class="fa-fw fa fa-film"></i><span> 电影</span></a></li><li><a class="site-page child" href="/blog/gallery/"><i class="fa-fw far fa-image"></i><span> 相册</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/blog/box/"><i class="fa-fw fab fa-xbox"></i><span> 聚宝盒</span></a></div><div class="menus_item"><a class="site-page" href="/blog/talk/"><i class="fa-fw far fa-comment"></i><span> 微语</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gitee.com/FIF/pic-beg/raw/master/images/vue/Hexo-logo.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">Jeffery Blog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 媒体</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/books/"><i class="fa-fw fas fa-book"></i><span> 阅读</span></a></li><li><a class="site-page child" href="/blog/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/blog/movies/"><i class="fa-fw fa fa-film"></i><span> 电影</span></a></li><li><a class="site-page child" href="/blog/gallery/"><i class="fa-fw far fa-image"></i><span> 相册</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/blog/box/"><i class="fa-fw fab fa-xbox"></i><span> 聚宝盒</span></a></div><div class="menus_item"><a class="site-page" href="/blog/talk/"><i class="fa-fw far fa-comment"></i><span> 微语</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Gitlab webhook 配置企业微信机器人</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-04-23T16:00:00.000Z" title="发表于 2021-04-24 00:00:00">2021-04-24</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-06-20T16:13:05.936Z" title="更新于 2021-06-21 00:13:05">2021-06-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/hexo/">hexo</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3.6k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>18分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Gitlab webhook 配置企业微信机器人"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Gitlab-webhook-配置企业微信机器人"><a href="#Gitlab-webhook-配置企业微信机器人" class="headerlink" title="Gitlab webhook 配置企业微信机器人"></a>Gitlab webhook 配置企业微信机器人</h1><h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><p>使用 <code>gitlab</code> 进行代码审查时，发现团队成员提交的代码不是很规范，有时候合并别的分支到开发分支造成分支污染，也不知道团队成员在什么时候提交的代码，线下审查代码和沟通很费时。为了提高代码审查的效率，事时查看团队成员提交合并的代码是否正确规范，于是想到使用 <code>GitLab</code> 提供的 <code>webhook</code> 钩子，搭建中间服务，利用企业微信机器人进行提醒，因为搭建 <code>CI/CD</code> 工具有点难，也有点大材小用，基于时间和精力成本。选择了前者。前前后后差不多用了两个星期完成。</p>
<h2 id="工作流程"><a href="#工作流程" class="headerlink" title="工作流程"></a>工作流程</h2><h3 id="Gitlab"><a href="#Gitlab" class="headerlink" title="Gitlab"></a>Gitlab</h3><p>在 <code>Gitlab</code> 的 <code>Integrations</code> 面板创建一条 <code>webhook</code> 记录，只有管理员才有权限创建，记录包括中间服务 <code>URL</code> 地址，勾选触发的事件，以及是否需要 SSL验证（可选）。</p>
<p><img src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/git/image-20210526203344528.png" alt="image-20210526203344528"></p>
<p><img src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/git/image-20210526203857017.png" alt="image-20210526203857017"></p>
<p>创建<code>webhook</code>成功后，当往 <code>gitlab</code> 仓库进行 当 <code>push、tag push、merge request、pipeline</code> 等操作，会触发勾选的钩子函数执行，携带 <code>git</code> 提交的信息的相关信息向 <code>URL</code> 地址发起一个请求，这时候我们搭建的中间服务就起作用了。它请求我们的中间服务地址，我们就可以拿到<code>gitlab</code>的请求信息，根据不同的提交操作进行逻辑处理，最后请求企业微信机器人发起</p>
<h2 id="技术选型"><a href="#技术选型" class="headerlink" title="技术选型"></a>技术选型</h2><p><a target="_blank" rel="noopener" href="https://www.bookstack.cn/read/gitlab-doc-zh/README.md">Gitlab 中文文档</a> </p>
<p><code>Gitlab</code> 提供 <code>webhook</code> 钩子，当 <code>push、tag push、merge request、pipeline</code> 等操作会触发 <code>webhook</code> 钩子函数执行, 请求 <code>webhook</code> 链接地址，<code>gitlab</code> 会把携带 <code>git</code> 提交的信息，在接口那里就可以通过请求头拿到需要的信息进行处理，然后调用企业微信提供的的 <a target="_blank" rel="noopener" href="https://open.work.weixin.qq.com/api/doc/90000/90136/91770">API</a> 服务通知机器人。所以，关键的核心步骤需要搭建一个中间服务，这里使用 <a target="_blank" rel="noopener" href="https://eggjs.org/zh-cn/intro/">eggjs</a> 框架搭建</p>
<h2 id="创建-webhook"><a href="#创建-webhook" class="headerlink" title="创建 webhook"></a>创建 webhook</h2><p>在 <code>gitlab</code> 的 webhook <code>URL</code> 上粘贴一条链接, 选择触发事件，点击 <code>Add webhook</code> 就可以创建一条 <code>webhook</code></p>
<p><a data-fancybox href="/images/gitlab/webhook.png"><img src= "" data-lazy-src="/images/gitlab/webhook.png" alt="挂载流程图"></a></p>
<p>中间服务搭建好后，可以测试 <code>webhook</code> ，点击 <code>Test</code> 可以选择触发的事件</p>
<p><a data-fancybox href="/images/gitlab/webhook-test.png"><img src= "" data-lazy-src="/images/gitlab/webhook-test.png" alt="挂载流程图"></a></p>
<h3 id="push-事件"><a href="#push-事件" class="headerlink" title="push 事件"></a>push 事件</h3><p>当提交代码 <code>push</code> 后，会把下面的对象放在请求头中，从中可以取出我们需要的信息</p>
<ul>
<li><code>object_kind</code>： 值是 <code>push</code>, 为 push 提交代码操作</li>
<li><code>ref</code>： 知道代码提交分支</li>
<li><code>user_name</code>： 提交人姓名</li>
<li><code>user_username</code>：提交人帐号</li>
<li><code>project</code>：通过 <code>name</code> 知道项目名称</li>
<li><code>commits</code>：<code>timestamp</code>、<code>url</code> 和 <code>msg</code> 可以拿到提交代码时间、提交代码路径、commit 信息记录</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">&quot;object_kind&quot;</span>: <span class="string">&quot;push&quot;</span>,</span><br><span class="line">  <span class="string">&quot;before&quot;</span>: <span class="string">&quot;95790bf891e76fee5e1747ab589903a6a1f80f22&quot;</span>,</span><br><span class="line">  <span class="string">&quot;after&quot;</span>: <span class="string">&quot;da1560886d4f094c3e6c9ef40349f7d38b5d27d7&quot;</span>,</span><br><span class="line">  <span class="string">&quot;ref&quot;</span>: <span class="string">&quot;refs/heads/master&quot;</span>,</span><br><span class="line">  <span class="string">&quot;checkout_sha&quot;</span>: <span class="string">&quot;da1560886d4f094c3e6c9ef40349f7d38b5d27d7&quot;</span>,</span><br><span class="line">  <span class="string">&quot;user_id&quot;</span>: <span class="number">4</span>,</span><br><span class="line">  <span class="string">&quot;user_name&quot;</span>: <span class="string">&quot;John Smith&quot;</span>,</span><br><span class="line">  <span class="string">&quot;user_username&quot;</span>: <span class="string">&quot;jsmith&quot;</span>,</span><br><span class="line">  <span class="string">&quot;user_email&quot;</span>: <span class="string">&quot;john@example.com&quot;</span>,</span><br><span class="line">  <span class="string">&quot;user_avatar&quot;</span>: <span class="string">&quot;https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80&quot;</span>,</span><br><span class="line">  <span class="string">&quot;project_id&quot;</span>: <span class="number">15</span>,</span><br><span class="line">  <span class="string">&quot;project&quot;</span>:&#123;</span><br><span class="line">    <span class="string">&quot;id&quot;</span>: <span class="number">15</span>,</span><br><span class="line">    <span class="string">&quot;name&quot;</span>:<span class="string">&quot;Diaspora&quot;</span>,</span><br><span class="line">    <span class="string">&quot;description&quot;</span>:<span class="string">&quot;&quot;</span>,</span><br><span class="line">    <span class="string">&quot;web_url&quot;</span>:<span class="string">&quot;http://example.com/mike/diaspora&quot;</span>,</span><br><span class="line">    <span class="string">&quot;avatar_url&quot;</span>:<span class="literal">null</span>,</span><br><span class="line">    <span class="string">&quot;git_ssh_url&quot;</span>:<span class="string">&quot;git@example.com:mike/diaspora.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;git_http_url&quot;</span>:<span class="string">&quot;http://example.com/mike/diaspora.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;namespace&quot;</span>:<span class="string">&quot;Mike&quot;</span>,</span><br><span class="line">    <span class="string">&quot;visibility_level&quot;</span>:<span class="number">0</span>,</span><br><span class="line">    <span class="string">&quot;path_with_namespace&quot;</span>:<span class="string">&quot;mike/diaspora&quot;</span>,</span><br><span class="line">    <span class="string">&quot;default_branch&quot;</span>:<span class="string">&quot;master&quot;</span>,</span><br><span class="line">    <span class="string">&quot;homepage&quot;</span>:<span class="string">&quot;http://example.com/mike/diaspora&quot;</span>,</span><br><span class="line">    <span class="string">&quot;url&quot;</span>:<span class="string">&quot;git@example.com:mike/diaspora.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;ssh_url&quot;</span>:<span class="string">&quot;git@example.com:mike/diaspora.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;http_url&quot;</span>:<span class="string">&quot;http://example.com/mike/diaspora.git&quot;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="string">&quot;repository&quot;</span>:&#123;</span><br><span class="line">    <span class="string">&quot;name&quot;</span>: <span class="string">&quot;Diaspora&quot;</span>,</span><br><span class="line">    <span class="string">&quot;url&quot;</span>: <span class="string">&quot;git@example.com:mike/diaspora.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;description&quot;</span>: <span class="string">&quot;&quot;</span>,</span><br><span class="line">    <span class="string">&quot;homepage&quot;</span>: <span class="string">&quot;http://example.com/mike/diaspora&quot;</span>,</span><br><span class="line">    <span class="string">&quot;git_http_url&quot;</span>:<span class="string">&quot;http://example.com/mike/diaspora.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;git_ssh_url&quot;</span>:<span class="string">&quot;git@example.com:mike/diaspora.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;visibility_level&quot;</span>:<span class="number">0</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="string">&quot;commits&quot;</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="string">&quot;id&quot;</span>: <span class="string">&quot;b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327&quot;</span>,</span><br><span class="line">      <span class="string">&quot;message&quot;</span>: <span class="string">&quot;Update Catalan translation to e38cb41.&quot;</span>,</span><br><span class="line">      <span class="string">&quot;timestamp&quot;</span>: <span class="string">&quot;2011-12-12T14:27:31+02:00&quot;</span>,</span><br><span class="line">      <span class="string">&quot;url&quot;</span>: <span class="string">&quot;http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327&quot;</span>,</span><br><span class="line">      <span class="string">&quot;author&quot;</span>: &#123;</span><br><span class="line">        <span class="string">&quot;name&quot;</span>: <span class="string">&quot;Jordi Mallach&quot;</span>,</span><br><span class="line">        <span class="string">&quot;email&quot;</span>: <span class="string">&quot;jordi@softcatala.org&quot;</span></span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="string">&quot;added&quot;</span>: [<span class="string">&quot;CHANGELOG&quot;</span>],</span><br><span class="line">      <span class="string">&quot;modified&quot;</span>: [<span class="string">&quot;app/controller/application.rb&quot;</span>],</span><br><span class="line">      <span class="string">&quot;removed&quot;</span>: []</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="string">&quot;id&quot;</span>: <span class="string">&quot;da1560886d4f094c3e6c9ef40349f7d38b5d27d7&quot;</span>,</span><br><span class="line">      <span class="string">&quot;message&quot;</span>: <span class="string">&quot;fixed readme&quot;</span>,</span><br><span class="line">      <span class="string">&quot;timestamp&quot;</span>: <span class="string">&quot;2012-01-03T23:36:29+02:00&quot;</span>,</span><br><span class="line">      <span class="string">&quot;url&quot;</span>: <span class="string">&quot;http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7&quot;</span>,</span><br><span class="line">      <span class="string">&quot;author&quot;</span>: &#123;</span><br><span class="line">        <span class="string">&quot;name&quot;</span>: <span class="string">&quot;GitLab dev user&quot;</span>,</span><br><span class="line">        <span class="string">&quot;email&quot;</span>: <span class="string">&quot;gitlabdev@dv6700.(none)&quot;</span></span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="string">&quot;added&quot;</span>: [<span class="string">&quot;CHANGELOG&quot;</span>],</span><br><span class="line">      <span class="string">&quot;modified&quot;</span>: [<span class="string">&quot;app/controller/application.rb&quot;</span>],</span><br><span class="line">      <span class="string">&quot;removed&quot;</span>: []</span><br><span class="line">    &#125;</span><br><span class="line">  ],</span><br><span class="line">  <span class="string">&quot;total_commits_count&quot;</span>: <span class="number">4</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="merge-request"><a href="#merge-request" class="headerlink" title="merge_request"></a>merge_request</h2><p>当发起合并、合并完成、关闭合并，会触发 <code>merge_request</code> 钩子，通过 <code>object_attributes.state</code> 值判断不同的操作，简单介绍一下需要的关键信息</p>
<ul>
<li>user: 提交人</li>
<li>object_attributes<ul>
<li>state：合并操作，opened - 发起合并，merged - 合并成功，closed - 关闭合并</li>
<li>url：合并详细地址</li>
<li>target_branch：合并目标分支</li>
<li>source_branch：合并源分支</li>
<li>created_at：合并时间</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">&quot;object_kind&quot;</span>: <span class="string">&quot;merge_request&quot;</span>,</span><br><span class="line">  <span class="string">&quot;user&quot;</span>: &#123;</span><br><span class="line">    <span class="string">&quot;name&quot;</span>: <span class="string">&quot;Administrator&quot;</span>,</span><br><span class="line">    <span class="string">&quot;username&quot;</span>: <span class="string">&quot;root&quot;</span>,</span><br><span class="line">    <span class="string">&quot;avatar_url&quot;</span>: <span class="string">&quot;http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon&quot;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="string">&quot;project&quot;</span>: &#123;</span><br><span class="line">    <span class="string">&quot;id&quot;</span>: <span class="number">1</span>,</span><br><span class="line">    <span class="string">&quot;name&quot;</span>:<span class="string">&quot;Gitlab Test&quot;</span>,</span><br><span class="line">    <span class="string">&quot;description&quot;</span>:<span class="string">&quot;Aut reprehenderit ut est.&quot;</span>,</span><br><span class="line">    <span class="string">&quot;web_url&quot;</span>:<span class="string">&quot;http://example.com/gitlabhq/gitlab-test&quot;</span>,</span><br><span class="line">    <span class="string">&quot;avatar_url&quot;</span>:<span class="literal">null</span>,</span><br><span class="line">    <span class="string">&quot;git_ssh_url&quot;</span>:<span class="string">&quot;git@example.com:gitlabhq/gitlab-test.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;git_http_url&quot;</span>:<span class="string">&quot;http://example.com/gitlabhq/gitlab-test.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;namespace&quot;</span>:<span class="string">&quot;GitlabHQ&quot;</span>,</span><br><span class="line">    <span class="string">&quot;visibility_level&quot;</span>:<span class="number">20</span>,</span><br><span class="line">    <span class="string">&quot;path_with_namespace&quot;</span>:<span class="string">&quot;gitlabhq/gitlab-test&quot;</span>,</span><br><span class="line">    <span class="string">&quot;default_branch&quot;</span>:<span class="string">&quot;master&quot;</span>,</span><br><span class="line">    <span class="string">&quot;homepage&quot;</span>:<span class="string">&quot;http://example.com/gitlabhq/gitlab-test&quot;</span>,</span><br><span class="line">    <span class="string">&quot;url&quot;</span>:<span class="string">&quot;http://example.com/gitlabhq/gitlab-test.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;ssh_url&quot;</span>:<span class="string">&quot;git@example.com:gitlabhq/gitlab-test.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;http_url&quot;</span>:<span class="string">&quot;http://example.com/gitlabhq/gitlab-test.git&quot;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="string">&quot;repository&quot;</span>: &#123;</span><br><span class="line">    <span class="string">&quot;name&quot;</span>: <span class="string">&quot;Gitlab Test&quot;</span>,</span><br><span class="line">    <span class="string">&quot;url&quot;</span>: <span class="string">&quot;http://example.com/gitlabhq/gitlab-test.git&quot;</span>,</span><br><span class="line">    <span class="string">&quot;description&quot;</span>: <span class="string">&quot;Aut reprehenderit ut est.&quot;</span>,</span><br><span class="line">    <span class="string">&quot;homepage&quot;</span>: <span class="string">&quot;http://example.com/gitlabhq/gitlab-test&quot;</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="string">&quot;object_attributes&quot;</span>: &#123;</span><br><span class="line">    <span class="string">&quot;id&quot;</span>: <span class="number">99</span>,</span><br><span class="line">    <span class="string">&quot;target_branch&quot;</span>: <span class="string">&quot;master&quot;</span>,</span><br><span class="line">    <span class="string">&quot;source_branch&quot;</span>: <span class="string">&quot;ms-viewport&quot;</span>,</span><br><span class="line">    <span class="string">&quot;source_project_id&quot;</span>: <span class="number">14</span>,</span><br><span class="line">    <span class="string">&quot;author_id&quot;</span>: <span class="number">51</span>,</span><br><span class="line">    <span class="string">&quot;assignee_id&quot;</span>: <span class="number">6</span>,</span><br><span class="line">    <span class="string">&quot;title&quot;</span>: <span class="string">&quot;MS-Viewport&quot;</span>,</span><br><span class="line">    <span class="string">&quot;created_at&quot;</span>: <span class="string">&quot;2013-12-03T17:23:34Z&quot;</span>,</span><br><span class="line">    <span class="string">&quot;updated_at&quot;</span>: <span class="string">&quot;2013-12-03T17:23:34Z&quot;</span>,</span><br><span class="line">    <span class="string">&quot;milestone_id&quot;</span>: <span class="literal">null</span>,</span><br><span class="line">    <span class="string">&quot;state&quot;</span>: <span class="string">&quot;opened&quot;</span>,</span><br><span class="line">    <span class="string">&quot;merge_status&quot;</span>: <span class="string">&quot;unchecked&quot;</span>,</span><br><span class="line">    <span class="string">&quot;target_project_id&quot;</span>: <span class="number">14</span>,</span><br><span class="line">    <span class="string">&quot;iid&quot;</span>: <span class="number">1</span>,</span><br><span class="line">    <span class="string">&quot;description&quot;</span>: <span class="string">&quot;&quot;</span>,</span><br><span class="line">    <span class="string">&quot;source&quot;</span>: &#123;</span><br><span class="line">      <span class="string">&quot;name&quot;</span>:<span class="string">&quot;Awesome Project&quot;</span>,</span><br><span class="line">      <span class="string">&quot;description&quot;</span>:<span class="string">&quot;Aut reprehenderit ut est.&quot;</span>,</span><br><span class="line">      <span class="string">&quot;web_url&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project&quot;</span>,</span><br><span class="line">      <span class="string">&quot;avatar_url&quot;</span>:<span class="literal">null</span>,</span><br><span class="line">      <span class="string">&quot;git_ssh_url&quot;</span>:<span class="string">&quot;git@example.com:awesome_space/awesome_project.git&quot;</span>,</span><br><span class="line">      <span class="string">&quot;git_http_url&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project.git&quot;</span>,</span><br><span class="line">      <span class="string">&quot;namespace&quot;</span>:<span class="string">&quot;Awesome Space&quot;</span>,</span><br><span class="line">      <span class="string">&quot;visibility_level&quot;</span>:<span class="number">20</span>,</span><br><span class="line">      <span class="string">&quot;path_with_namespace&quot;</span>:<span class="string">&quot;awesome_space/awesome_project&quot;</span>,</span><br><span class="line">      <span class="string">&quot;default_branch&quot;</span>:<span class="string">&quot;master&quot;</span>,</span><br><span class="line">      <span class="string">&quot;homepage&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project&quot;</span>,</span><br><span class="line">      <span class="string">&quot;url&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project.git&quot;</span>,</span><br><span class="line">      <span class="string">&quot;ssh_url&quot;</span>:<span class="string">&quot;git@example.com:awesome_space/awesome_project.git&quot;</span>,</span><br><span class="line">      <span class="string">&quot;http_url&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project.git&quot;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="string">&quot;target&quot;</span>: &#123;</span><br><span class="line">      <span class="string">&quot;name&quot;</span>:<span class="string">&quot;Awesome Project&quot;</span>,</span><br><span class="line">      <span class="string">&quot;description&quot;</span>:<span class="string">&quot;Aut reprehenderit ut est.&quot;</span>,</span><br><span class="line">      <span class="string">&quot;web_url&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project&quot;</span>,</span><br><span class="line">      <span class="string">&quot;avatar_url&quot;</span>:<span class="literal">null</span>,</span><br><span class="line">      <span class="string">&quot;git_ssh_url&quot;</span>:<span class="string">&quot;git@example.com:awesome_space/awesome_project.git&quot;</span>,</span><br><span class="line">      <span class="string">&quot;git_http_url&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project.git&quot;</span>,</span><br><span class="line">      <span class="string">&quot;namespace&quot;</span>:<span class="string">&quot;Awesome Space&quot;</span>,</span><br><span class="line">      <span class="string">&quot;visibility_level&quot;</span>:<span class="number">20</span>,</span><br><span class="line">      <span class="string">&quot;path_with_namespace&quot;</span>:<span class="string">&quot;awesome_space/awesome_project&quot;</span>,</span><br><span class="line">      <span class="string">&quot;default_branch&quot;</span>:<span class="string">&quot;master&quot;</span>,</span><br><span class="line">      <span class="string">&quot;homepage&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project&quot;</span>,</span><br><span class="line">      <span class="string">&quot;url&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project.git&quot;</span>,</span><br><span class="line">      <span class="string">&quot;ssh_url&quot;</span>:<span class="string">&quot;git@example.com:awesome_space/awesome_project.git&quot;</span>,</span><br><span class="line">      <span class="string">&quot;http_url&quot;</span>:<span class="string">&quot;http://example.com/awesome_space/awesome_project.git&quot;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="string">&quot;last_commit&quot;</span>: &#123;</span><br><span class="line">      <span class="string">&quot;id&quot;</span>: <span class="string">&quot;da1560886d4f094c3e6c9ef40349f7d38b5d27d7&quot;</span>,</span><br><span class="line">      <span class="string">&quot;message&quot;</span>: <span class="string">&quot;fixed readme&quot;</span>,</span><br><span class="line">      <span class="string">&quot;timestamp&quot;</span>: <span class="string">&quot;2012-01-03T23:36:29+02:00&quot;</span>,</span><br><span class="line">      <span class="string">&quot;url&quot;</span>: <span class="string">&quot;http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7&quot;</span>,</span><br><span class="line">      <span class="string">&quot;author&quot;</span>: &#123;</span><br><span class="line">        <span class="string">&quot;name&quot;</span>: <span class="string">&quot;GitLab dev user&quot;</span>,</span><br><span class="line">        <span class="string">&quot;email&quot;</span>: <span class="string">&quot;gitlabdev@dv6700.(none)&quot;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="string">&quot;work_in_progress&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">    <span class="string">&quot;url&quot;</span>: <span class="string">&quot;http://example.com/diaspora/merge_requests/1&quot;</span>,</span><br><span class="line">    <span class="string">&quot;action&quot;</span>: <span class="string">&quot;open&quot;</span>,</span><br><span class="line">    <span class="string">&quot;assignee&quot;</span>: &#123;</span><br><span class="line">      <span class="string">&quot;name&quot;</span>: <span class="string">&quot;User1&quot;</span>,</span><br><span class="line">      <span class="string">&quot;username&quot;</span>: <span class="string">&quot;user1&quot;</span>,</span><br><span class="line">      <span class="string">&quot;avatar_url&quot;</span>: <span class="string">&quot;http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="string">&quot;labels&quot;</span>: [&#123;</span><br><span class="line">    <span class="string">&quot;id&quot;</span>: <span class="number">206</span>,</span><br><span class="line">    <span class="string">&quot;title&quot;</span>: <span class="string">&quot;API&quot;</span>,</span><br><span class="line">    <span class="string">&quot;color&quot;</span>: <span class="string">&quot;#ffffff&quot;</span>,</span><br><span class="line">    <span class="string">&quot;project_id&quot;</span>: <span class="number">14</span>,</span><br><span class="line">    <span class="string">&quot;created_at&quot;</span>: <span class="string">&quot;2013-12-03T17:15:43Z&quot;</span>,</span><br><span class="line">    <span class="string">&quot;updated_at&quot;</span>: <span class="string">&quot;2013-12-03T17:15:43Z&quot;</span>,</span><br><span class="line">    <span class="string">&quot;template&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">    <span class="string">&quot;description&quot;</span>: <span class="string">&quot;API related issues&quot;</span>,</span><br><span class="line">    <span class="string">&quot;type&quot;</span>: <span class="string">&quot;ProjectLabel&quot;</span>,</span><br><span class="line">    <span class="string">&quot;group_id&quot;</span>: <span class="number">41</span></span><br><span class="line">  &#125;],</span><br><span class="line">  <span class="string">&quot;changes&quot;</span>: &#123;</span><br><span class="line">    <span class="string">&quot;updated_by_id&quot;</span>: [<span class="literal">null</span>, <span class="number">1</span>],</span><br><span class="line">    <span class="string">&quot;updated_at&quot;</span>: [<span class="string">&quot;2017-09-15 16:50:55 UTC&quot;</span>, <span class="string">&quot;2017-09-15 16:52:00 UTC&quot;</span>],</span><br><span class="line">    <span class="string">&quot;labels&quot;</span>: &#123;</span><br><span class="line">      <span class="string">&quot;previous&quot;</span>: [&#123;</span><br><span class="line">        <span class="string">&quot;id&quot;</span>: <span class="number">206</span>,</span><br><span class="line">        <span class="string">&quot;title&quot;</span>: <span class="string">&quot;API&quot;</span>,</span><br><span class="line">        <span class="string">&quot;color&quot;</span>: <span class="string">&quot;#ffffff&quot;</span>,</span><br><span class="line">        <span class="string">&quot;project_id&quot;</span>: <span class="number">14</span>,</span><br><span class="line">        <span class="string">&quot;created_at&quot;</span>: <span class="string">&quot;2013-12-03T17:15:43Z&quot;</span>,</span><br><span class="line">        <span class="string">&quot;updated_at&quot;</span>: <span class="string">&quot;2013-12-03T17:15:43Z&quot;</span>,</span><br><span class="line">        <span class="string">&quot;template&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">        <span class="string">&quot;description&quot;</span>: <span class="string">&quot;API related issues&quot;</span>,</span><br><span class="line">        <span class="string">&quot;type&quot;</span>: <span class="string">&quot;ProjectLabel&quot;</span>,</span><br><span class="line">        <span class="string">&quot;group_id&quot;</span>: <span class="number">41</span></span><br><span class="line">      &#125;],</span><br><span class="line">      <span class="string">&quot;current&quot;</span>: [&#123;</span><br><span class="line">        <span class="string">&quot;id&quot;</span>: <span class="number">205</span>,</span><br><span class="line">        <span class="string">&quot;title&quot;</span>: <span class="string">&quot;Platform&quot;</span>,</span><br><span class="line">        <span class="string">&quot;color&quot;</span>: <span class="string">&quot;#123123&quot;</span>,</span><br><span class="line">        <span class="string">&quot;project_id&quot;</span>: <span class="number">14</span>,</span><br><span class="line">        <span class="string">&quot;created_at&quot;</span>: <span class="string">&quot;2013-12-03T17:15:43Z&quot;</span>,</span><br><span class="line">        <span class="string">&quot;updated_at&quot;</span>: <span class="string">&quot;2013-12-03T17:15:43Z&quot;</span>,</span><br><span class="line">        <span class="string">&quot;template&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">        <span class="string">&quot;description&quot;</span>: <span class="string">&quot;Platform related issues&quot;</span>,</span><br><span class="line">        <span class="string">&quot;type&quot;</span>: <span class="string">&quot;ProjectLabel&quot;</span>,</span><br><span class="line">        <span class="string">&quot;group_id&quot;</span>: <span class="number">41</span></span><br><span class="line">      &#125;]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="搭建中间服务"><a href="#搭建中间服务" class="headerlink" title="搭建中间服务"></a>搭建中间服务</h2><p>使用 <a target="_blank" rel="noopener" href="https://eggjs.org/zh-cn/intro/quickstart.html">eggjs</a> 框架快速搭建项目</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> mkdir gitlab-webhook &amp;&amp; <span class="built_in">cd</span> gitlab-webhook</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> npm init egg --<span class="built_in">type</span>= // 初始化项目</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> npm i // 按照依赖</span></span><br></pre></td></tr></table></figure>

<p><strong>创建路由</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// gitlab-webhook/app/router.js</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = <span class="function"><span class="params">app</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">const</span> &#123; router, controller &#125; = app;</span><br><span class="line">  router.get(<span class="string">&#x27;/&#x27;</span>, controller.home.index);</span><br><span class="line">  router.post(<span class="string">&#x27;/webhook/:key&#x27;</span>, controller.home.webhook);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p><strong>创建控制器类</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// gitlab-webhook/app/controller/home.js</span></span><br><span class="line"></span><br><span class="line"><span class="meta">&#x27;use strict&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> Controller = <span class="built_in">require</span>(<span class="string">&#x27;egg&#x27;</span>).Controller;</span><br><span class="line"><span class="keyword">const</span> config = <span class="built_in">require</span>(<span class="string">&#x27;../../config/config&#x27;</span>);</span><br><span class="line"><span class="keyword">const</span> events = <span class="built_in">require</span>(<span class="string">&#x27;../core/events/index&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">HomeController</span> <span class="keyword">extends</span> <span class="title">Controller</span> </span>&#123;</span><br><span class="line">  <span class="keyword">async</span> <span class="function"><span class="title">index</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> &#123; ctx &#125; = <span class="built_in">this</span>;</span><br><span class="line">    ctx.body = <span class="string">&#x27;hi, egg&#x27;</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">// gitlab webhook &amp;&amp; 企业微信机器人</span></span><br><span class="line">  <span class="keyword">async</span> <span class="function"><span class="title">webhook</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> &#123; ctx, app &#125; = <span class="built_in">this</span>;</span><br><span class="line">    <span class="keyword">const</span> body = ctx.request.body;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> key = ctx.params.key;</span><br><span class="line">    <span class="keyword">if</span> (!key) <span class="keyword">return</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 拼接 webhook 链接地址，发送企业微信机器人地址</span></span><br><span class="line">    <span class="keyword">const</span> webhook = config.baseWebhook + key;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">      <span class="keyword">const</span> eventType = body.object_kind;</span><br><span class="line">      <span class="comment">// push 推送事件</span></span><br><span class="line">      <span class="keyword">if</span> (eventType === <span class="string">&#x27;push&#x27;</span>) &#123;</span><br><span class="line">        <span class="keyword">await</span> events.pushEvent(ctx, webhook, body);</span><br><span class="line">      &#125; <span class="keyword">else</span> <span class="keyword">if</span> (eventType === <span class="string">&#x27;merge_request&#x27;</span>) &#123;</span><br><span class="line">        <span class="keyword">await</span> events.mergeEvent(ctx, webhook, body);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125; <span class="keyword">catch</span> (ex) &#123;</span><br><span class="line">      <span class="built_in">console</span>.log(ex);</span><br><span class="line">      <span class="built_in">this</span>.ctx.body = <span class="string">&#x27;请求参数不合法&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = HomeController;</span><br></pre></td></tr></table></figure>

<p><strong>pull 事件处理</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// gitlab-webhook/core/event/push.js</span></span><br><span class="line"></span><br><span class="line"><span class="meta">&#x27;use strict&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> config = <span class="built_in">require</span>(<span class="string">&#x27;../../../config/config&#x27;</span>);</span><br><span class="line"><span class="keyword">const</span> utils = <span class="built_in">require</span>(<span class="string">&#x27;../utils/index&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">function</span> <span class="title">pushEvent</span>(<span class="params">ctx, webhook, body</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">try</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> &#123; project, commits, ref &#125; = body;</span><br><span class="line">    <span class="comment">// 提交人</span></span><br><span class="line">    <span class="keyword">const</span> commitPerson = config.commitPeople[body.user_username] || config.commitPeople[body.user_name];</span><br><span class="line">    <span class="keyword">const</span> username = commitPerson &amp;&amp; commitPerson.name || body.user_name;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 提交记录</span></span><br><span class="line">    <span class="keyword">const</span> commit = <span class="built_in">Array</span>.isArray(commits) &amp;&amp; commits[commits.length - <span class="number">1</span>];</span><br><span class="line">    <span class="keyword">const</span> dateFormat = utils.getDateFormat(commit.timestamp);</span><br><span class="line">    <span class="keyword">const</span> lastCommit = commit.message;</span><br><span class="line">    <span class="keyword">const</span> pushUrl = commit.url;</span><br><span class="line">    <span class="keyword">const</span> projectName = project.name;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> receivers = config.receivers;</span><br><span class="line">    <span class="comment">// 验证接收者</span></span><br><span class="line">    <span class="keyword">if</span> (!(commitPerson || receivers.includes(username))) &#123;</span><br><span class="line">      <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">let</span> sourceBranch = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line">    <span class="keyword">if</span> (ref) &#123;</span><br><span class="line">      <span class="keyword">const</span> branch = ref.split(<span class="string">&#x27;/&#x27;</span>);</span><br><span class="line">      sourceBranch = branch[branch.length - <span class="number">1</span>];</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> msg = <span class="string">`\*\*push 提交成功，请及时查看\*\*</span></span><br><span class="line"><span class="string">      \&gt;提交人：<span class="subst">$&#123;username&#125;</span></span></span><br><span class="line"><span class="string">      \&gt;时间：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;dateFormat&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">      \&gt;项目：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;projectName&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">      \&gt;提交分支：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;sourceBranch || <span class="string">&#x27;未知&#x27;</span>&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">      \&gt;最后提交信息：&lt;font color=\&quot;info\&quot;&gt; <span class="subst">$&#123;lastCommit&#125;</span> &lt;/font&gt;</span></span><br><span class="line"><span class="string">      \&gt;请求链接：[<span class="subst">$&#123;pushUrl&#125;</span>](<span class="subst">$&#123;pushUrl&#125;</span>)`</span>;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">await</span> ctx.curl(webhook, &#123;</span><br><span class="line">      method: <span class="string">&#x27;POST&#x27;</span>,</span><br><span class="line">      contentType: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">      data: &#123;</span><br><span class="line">        msgtype: <span class="string">&#x27;markdown&#x27;</span>,</span><br><span class="line">        markdown: &#123;</span><br><span class="line">          content: msg,</span><br><span class="line">        &#125;,</span><br><span class="line">      &#125;,</span><br><span class="line">      dataType: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">await</span> ctx.curl(webhook, &#123;</span><br><span class="line">      method: <span class="string">&#x27;POST&#x27;</span>,</span><br><span class="line">      contentType: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">      data: &#123;</span><br><span class="line">        msgtype: <span class="string">&#x27;text&#x27;</span>,</span><br><span class="line">        text: &#123;</span><br><span class="line">          content: <span class="string">`@<span class="subst">$&#123;username&#125;</span>`</span>,</span><br><span class="line">        &#125;,</span><br><span class="line">      &#125;,</span><br><span class="line">      dataType: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    ctx.body = <span class="string">&#x27;消息推送成功！&#x27;</span>;</span><br><span class="line">  &#125; <span class="keyword">catch</span> (error) &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(error);</span><br><span class="line">    ctx.body = <span class="string">&#x27;请求参数不合法&#x27;</span>;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  pushEvent,</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>合并事件处理</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&#x27;use strict&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> config = <span class="built_in">require</span>(<span class="string">&#x27;../../../config/config&#x27;</span>);</span><br><span class="line"><span class="keyword">const</span> utils = <span class="built_in">require</span>(<span class="string">&#x27;../utils/index&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">function</span> <span class="title">mergeEvent</span>(<span class="params">ctx, webhook, body</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">try</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> &#123; user, project, object_attributes &#125; = body;</span><br><span class="line">    <span class="keyword">const</span> commitPerson = config.commitPeople[user.username] || config.commitPeople[user.name];</span><br><span class="line">    <span class="keyword">const</span> username = commitPerson &amp;&amp; commitPerson.name || user.name || user.username;</span><br><span class="line">    <span class="keyword">const</span> projectName = project &amp;&amp; project.name;</span><br><span class="line">    <span class="keyword">let</span> stateType = <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      mergeUrl = <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      targetBranch = <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      sourceBranch = <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      lastCommit = <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      requestPerson = <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      dateFormat = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (object_attributes) &#123;</span><br><span class="line">      <span class="keyword">const</span> &#123; state, url, created_at, target_branch, source_branch, last_commit &#125; = object_attributes;</span><br><span class="line">      stateType = state;</span><br><span class="line">      mergeUrl = url;</span><br><span class="line">      targetBranch = target_branch;</span><br><span class="line">      sourceBranch = source_branch;</span><br><span class="line">      lastCommit = last_commit ? last_commit.message : <span class="string">&#x27;&#x27;</span>;</span><br><span class="line">      <span class="keyword">const</span> lastCommitUserArr = lastCommit.match(</span><br><span class="line">        /--user=[a-zA-Z\d\u4e00-\u9fa5]+\s&#123;<span class="number">0</span>,<span class="number">1</span>&#125;/g</span><br><span class="line">      );</span><br><span class="line">      requestPerson =</span><br><span class="line">        lastCommitUserArr &amp;&amp; lastCommitUserArr[<span class="number">0</span>]</span><br><span class="line">          ? lastCommitUserArr[<span class="number">0</span>].replace(<span class="regexp">/--user=/g</span>, <span class="string">&#x27;&#x27;</span>).replace(<span class="regexp">/\s+/g</span>, <span class="string">&#x27;&#x27;</span>)</span><br><span class="line">          : <span class="literal">null</span>;</span><br><span class="line"></span><br><span class="line">      <span class="comment">// 提交时间</span></span><br><span class="line">      <span class="keyword">if</span> (created_at) &#123;</span><br><span class="line">        dateFormat = utils.getDateFormat(created_at);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> receivers = config.receivers;</span><br><span class="line">    <span class="comment">// 验证接收者</span></span><br><span class="line">    <span class="keyword">if</span> (!(commitPerson || receivers.includes(username))) &#123;</span><br><span class="line">      <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">let</span> msg = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line">    <span class="keyword">let</span> isSend = <span class="literal">false</span>;</span><br><span class="line">    <span class="keyword">switch</span> (stateType) &#123;</span><br><span class="line">      <span class="keyword">case</span> <span class="string">&#x27;opened&#x27;</span>:</span><br><span class="line">        <span class="comment">// 发起合并请求</span></span><br><span class="line">        msg = <span class="string">`\*\*发起了一个合并请求，请及时查看\*\*</span></span><br><span class="line"><span class="string">                \&gt;发起人：<span class="subst">$&#123;username&#125;</span></span></span><br><span class="line"><span class="string">                \&gt;时间：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;dateFormat&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;项目：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;projectName&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;来源分支：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;sourceBranch&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;目标分支：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;targetBranch&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;最后提交信息：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;lastCommit&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;请求链接：[<span class="subst">$&#123;mergeUrl&#125;</span>](<span class="subst">$&#123;mergeUrl&#125;</span>)`</span>;</span><br><span class="line">        isSend = <span class="literal">true</span>;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      <span class="keyword">case</span> <span class="string">&#x27;merged&#x27;</span>:</span><br><span class="line">        <span class="comment">// 合并成功</span></span><br><span class="line">        msg = <span class="string">`\*\*合并请求已完成\*\*</span></span><br><span class="line"><span class="string">                \&gt;发起人：<span class="subst">$&#123;requestPerson || <span class="string">&#x27;未知&#x27;</span>&#125;</span></span></span><br><span class="line"><span class="string">                \&gt;合并人：<span class="subst">$&#123;username&#125;</span></span></span><br><span class="line"><span class="string">                \&gt;时间：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;dateFormat&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;项目：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;projectName&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;来源分支：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;sourceBranch&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;目标分支：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;targetBranch&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;最后提交信息：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;lastCommit&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;请求链接：[<span class="subst">$&#123;mergeUrl&#125;</span>](<span class="subst">$&#123;mergeUrl&#125;</span>)`</span>;</span><br><span class="line">        isSend = <span class="literal">true</span>;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      <span class="keyword">case</span> <span class="string">&#x27;closed&#x27;</span>:</span><br><span class="line">        <span class="comment">// 请求关闭</span></span><br><span class="line">        msg = <span class="string">`\*\*合并请求已关闭\*\*</span></span><br><span class="line"><span class="string">                \&gt;发起人：<span class="subst">$&#123;requestPerson || <span class="string">&#x27;未知&#x27;</span>&#125;</span></span></span><br><span class="line"><span class="string">                \&gt;关闭人：<span class="subst">$&#123;username&#125;</span></span></span><br><span class="line"><span class="string">                \&gt;时间：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;dateFormat&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;项目：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;projectName&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;来源分支：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;sourceBranch&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;目标分支：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;targetBranch&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;最后提交信息：&lt;font color=\&quot;info\&quot;&gt;<span class="subst">$&#123;lastCommit&#125;</span>&lt;/font&gt;</span></span><br><span class="line"><span class="string">                \&gt;请求链接：[<span class="subst">$&#123;mergeUrl&#125;</span>](<span class="subst">$&#123;mergeUrl&#125;</span>)`</span>;</span><br><span class="line">        isSend = <span class="literal">true</span>;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      <span class="keyword">default</span>:</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (isSend) &#123;</span><br><span class="line">      <span class="keyword">await</span> ctx.curl(webhook, &#123;</span><br><span class="line">        method: <span class="string">&#x27;POST&#x27;</span>,</span><br><span class="line">        contentType: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">        data: &#123;</span><br><span class="line">          msgtype: <span class="string">&#x27;markdown&#x27;</span>,</span><br><span class="line">          markdown: &#123;</span><br><span class="line">            content: msg,</span><br><span class="line">          &#125;,</span><br><span class="line">        &#125;,</span><br><span class="line">        dataType: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">      &#125;);</span><br><span class="line"></span><br><span class="line">      <span class="keyword">await</span> ctx.curl(webhook, &#123;</span><br><span class="line">        method: <span class="string">&#x27;POST&#x27;</span>,</span><br><span class="line">        contentType: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">        data: &#123;</span><br><span class="line">          msgtype: <span class="string">&#x27;text&#x27;</span>,</span><br><span class="line">          text: &#123;</span><br><span class="line">            content: <span class="string">`@<span class="subst">$&#123;username&#125;</span>`</span>,</span><br><span class="line">          &#125;,</span><br><span class="line">        &#125;,</span><br><span class="line">        dataType: <span class="string">&#x27;json&#x27;</span>,</span><br><span class="line">      &#125;);</span><br><span class="line">      <span class="built_in">this</span>.ctx.body = <span class="string">&#x27;消息推送成功！&#x27;</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      <span class="built_in">this</span>.ctx.body = <span class="string">&#x27;消息类型$&#123;stateType&#125;不合法&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">  &#125; <span class="keyword">catch</span> (error) &#123;</span><br><span class="line">    <span class="built_in">console</span>.error(error);</span><br><span class="line">    <span class="built_in">this</span>.ctx.body = <span class="string">&#x27;请求参数不合法&#x27;</span>;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  mergeEvent,</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p><strong>企业微信机器人配置</strong></p>
<p>在企业微信机器人群聊中可以直接创建机器人，拿到机器人通知地址，在服务端通过配置需要的标题、文本、图片等字段，请求接口就可以通知到企业微信。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">await</span> ctx.curl(webhook, &#123;</span><br><span class="line">  method: <span class="string">&#x27;POST&#x27;</span>,</span><br><span class="line">  contentType: <span class="string">&#x27;json&#x27;</span>, <span class="comment">// 内容类型</span></span><br><span class="line">  data: &#123;</span><br><span class="line">    msgtype: <span class="string">&#x27;markdown&#x27;</span>, <span class="comment">// 文本格式 markdown</span></span><br><span class="line">    markdown: &#123;</span><br><span class="line">      content: msg, <span class="comment">// 显示文本</span></span><br><span class="line">    &#125;,</span><br><span class="line">  &#125;,</span><br><span class="line">  dataType: <span class="string">&#x27;json&#x27;</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p><strong>配置界面显示</strong></p>
<p><a data-fancybox href="/images/gitlab/qiyeweixin.png"><img src= "" data-lazy-src="/images/gitlab/qiyeweixin.png" alt="挂载流程图"></a></p>
<p>整个过程还是挺简单的，不过中间要定制webhook, 对特定的人特定的分支进行提醒，需要做处理，源码仓库地址在这里<a target="_blank" rel="noopener" href="https://github.com/JefferyXZF/qw-gitlab-webhook">github</a>，感兴趣欢迎提PR</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">志非</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://fif.gitee.io/blog/2021/04/24/tools/gitlab/index/">https://fif.gitee.io/blog/2021/04/24/tools/gitlab/index/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://fif.gitee.io/blog" target="_blank">Jeffery Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/hexo/">hexo</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/FIF/pic-beg/raw/master/images/vue/Hexo-logo.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2021/04/27/vue/vue-code-6.reactive/"><img class="prev-cover" src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/vue/mvvm.png" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">（Vue源码四）数据响应式原理</div></div></a></div><div class="next-post pull-right"><a href="/blog/2021/04/23/vue/vue-code-5.mergeOptions/"><img class="next-cover" src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/vue/vue-highcharts_1200.webp" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">（Vue源码三）Vue 丰富的选项合并策略</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2021/05/24/tools/hexo/advanced/" title="Hexo 博客页面性能优化"><img class="cover" src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/vue/Hexo-logo.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-05-24</div><div class="title">Hexo 博客页面性能优化</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src= "" data-lazy-src="/blog/img/home/avatar.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">志非</div><div class="author-info__description">自己变得更好，生活才会更美好</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">12</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">6</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/JefferyXZF"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/JefferyXZF" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://www.yuque.com/jeffery-kkrpn/uz24n9" target="_blank" title="语雀"><i class="fa fa-folder-open"></i></a><a class="social-icon" href="https://mail.qq.com/" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">越努力越幸运</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Gitlab-webhook-%E9%85%8D%E7%BD%AE%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%9C%BA%E5%99%A8%E4%BA%BA"><span class="toc-number">1.</span> <span class="toc-text">Gitlab webhook 配置企业微信机器人</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A6%82%E8%BF%B0"><span class="toc-number">1.1.</span> <span class="toc-text">概述</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B"><span class="toc-number">1.2.</span> <span class="toc-text">工作流程</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Gitlab"><span class="toc-number">1.2.1.</span> <span class="toc-text">Gitlab</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8A%80%E6%9C%AF%E9%80%89%E5%9E%8B"><span class="toc-number">1.3.</span> <span class="toc-text">技术选型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA-webhook"><span class="toc-number">1.4.</span> <span class="toc-text">创建 webhook</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#push-%E4%BA%8B%E4%BB%B6"><span class="toc-number">1.4.1.</span> <span class="toc-text">push 事件</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#merge-request"><span class="toc-number">1.5.</span> <span class="toc-text">merge_request</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%90%AD%E5%BB%BA%E4%B8%AD%E9%97%B4%E6%9C%8D%E5%8A%A1"><span class="toc-number">1.6.</span> <span class="toc-text">搭建中间服务</span></a></li></ol></li></ol></div></div><script defer="defer" data-pjax="data-pjax" src="/blog/js/card_clock.js"></script><div class="card-widget card-clock"><div id="clock"><img v-if="clockshow == &quot;false&quot;" alt="" src= "" data-lazy-src="/blog/img/weather/loading.gif" height="120px" width="100%"/><table class="clock" v-if="clockshow"><tbody><tr><td class="clockdate">{{date}}</td><td class="weatherimg"><img id="weatherimg" :src="weatherimg" alt=""/></td><td class="temperature">{{temperature}}</td><td class="humidityimg"><img id="humidityimg" :src="humidityimg" alt=""/></td><td class="humidity">{{humidity}}</td></tr><tr class="time"><td colspan="5">{{time}}</td></tr><tr><td class="usaqi" colspan="1"><span>{{ip}}</span></td><td class="city" colspan="2">{{city}}</td><td class="daylight" colspan="2">{{daylight}}</td></tr></tbody></table></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/05/24/tools/hexo/advanced/" title="Hexo 博客页面性能优化"><img src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/vue/Hexo-logo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Hexo 博客页面性能优化"/></a><div class="content"><a class="title" href="/blog/2021/05/24/tools/hexo/advanced/" title="Hexo 博客页面性能优化">Hexo 博客页面性能优化</a><time datetime="2021-05-23T16:00:00.000Z" title="发表于 2021-05-24 00:00:00">2021-05-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/05/14/vue/vue-code-9.event/" title="（Vue源码七）Vue 事件"><img src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/vue/components.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="（Vue源码七）Vue 事件"/></a><div class="content"><a class="title" href="/blog/2021/05/14/vue/vue-code-9.event/" title="（Vue源码七）Vue 事件">（Vue源码七）Vue 事件</a><time datetime="2021-05-13T16:00:00.000Z" title="发表于 2021-05-14 00:00:00">2021-05-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/05/04/vue/vue-code-8.component/" title="（Vue源码六）Vue 组件原理分析"><img src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/vue/components.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="（Vue源码六）Vue 组件原理分析"/></a><div class="content"><a class="title" href="/blog/2021/05/04/vue/vue-code-8.component/" title="（Vue源码六）Vue 组件原理分析">（Vue源码六）Vue 组件原理分析</a><time datetime="2021-05-03T16:00:00.000Z" title="发表于 2021-05-04 00:00:00">2021-05-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/04/30/vue/vue-code-7-compiler/" title="（Vue源码五）Vue 编译原理"><img src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/vue/vuetemplate.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="（Vue源码五）Vue 编译原理"/></a><div class="content"><a class="title" href="/blog/2021/04/30/vue/vue-code-7-compiler/" title="（Vue源码五）Vue 编译原理">（Vue源码五）Vue 编译原理</a><time datetime="2021-04-29T16:00:00.000Z" title="发表于 2021-04-30 00:00:00">2021-04-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/04/27/vue/vue-code-6.reactive/" title="（Vue源码四）数据响应式原理"><img src= "" data-lazy-src="https://gitee.com/FIF/pic-beg/raw/master/images/vue/mvvm.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="（Vue源码四）数据响应式原理"/></a><div class="content"><a class="title" href="/blog/2021/04/27/vue/vue-code-6.reactive/" title="（Vue源码四）数据响应式原理">（Vue源码四）数据响应式原理</a><time datetime="2021-04-26T16:00:00.000Z" title="发表于 2021-04-27 00:00:00">2021-04-27</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 By 志非</div><div class="footer_custom_text">Hi, welcome to my <a href="/">blog</a>!</div><div id="workboard"></div><script async="async" src="/blog/js/runtime.js"></script></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="algolia-search"><div class="search-dialog"><div class="search-dialog__title" id="algolia-search-title">Algolia</div><div id="algolia-input-panel"><div id="algolia-search-input"></div></div><hr/><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-stats"></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/vue"></script><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="/blog/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/blog/js/search/algolia.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      false && mermaid.init()
    })
  }
}</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'JC72d1A7XBwC26rGCKMVn5CS-MdYXbMMI',
      appKey: 'xI6bG7FseICz8ShKdmWVe7N1',
      placeholder: 'Please leave your footprints',
      avatar: 'https://gitee.com/FIF/pic-beg/raw/master/images/vue/1619248532079-avatar_coment.webp',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      requiredFields: ["nick,mail"],
      visitor: false,
      avatar_cdn: 'https://www.gravatar.com/avatar/'
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><div class="aplayer no-destroy" data-id="000PeZCQ1i4XVs" data-server="tencent" data-type="artist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="false" pjax="true" muted></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>